$(document).ready(function(){
	// 下拉框
	$(".input-box").click(function(e){
		$(('#'+ e.currentTarget.id +' '+".form-list")).show()
	});
	$(".form-list li").click(function(e){
		$('#'+$(this).parent().parent(".input-box")[0].id + ' ' + '.form-text').text($(this).text());
		$(".form-list").hide();
		event.stopPropagation();
	});
	$(".join_btn").click(check);
    var poiaddress = sessionStorage.getItem("poiaddress");
    var joinInfomation = JSON.parse(sessionStorage.getItem("joinInfomation"));
    if(poiaddress) {
	$("#location .form-text").text(poiaddress);
	}
	if(joinInfomation) {
        $("#city .form-text").text(joinInfomation.city),
		$("#company").val(joinInfomation.company),
		$("#office .form-text").text(joinInfomation.staffNum),
		$("#job .form-text").text(joinInfomation.job),
		$("#phone").val(joinInfomation.phone)
	}
})
function submit (){
	var orderQuery = "user/feedback/add"
	var orderQueryParams = {
		"TYPE_ID" : "7",
		"TYPE": "企业入驻",
		"CONTENT": "所在城市："+ $("#city .form-text").text() + "，公司名称："+ $("#company").val() + ",公司所在地址：" + $("#location .form-text").text() + ",办公室常驻人数:"+($("#office .form-text").text() + ",职务:" + $("#job .form-text").text()) + "，手机号：" + $("#phone").val(),
		"PHONE_NO": $("#phone").val(),
		"STORE_ID":STORE_ID
	}
	request(orderQuery, orderQueryParams, function (res){
        var flg = /^0+$/ig.test(res.RSPCD); //全零true
        if(flg) {
            location.replace("./feed_back_success.html?noticeText=join_us");
        }
	})
}
function check (){
	if($("#city .form-text").text() == "请选择城市"){
		return alert("请选择城市");
	}
	else if($("#company").val() == ""){
		return alert("请填写公司名称");
	}
	else if($("#location .form-text").text() == "请选择公司地址"){
		return alert("请选择公司地址");
	}
	else if($("#office .form-text").text() == "请选择办公室常驻人数"){
		return alert("请选择办公室常驻人数")
	}
	else if($("#job .form-text").text() == "请选择您的职务"){
		return alert("请选择您的职务");
	}
	else if(!phoneCHeck($("#phone").val())){
		return alert("请正确填写您的手机号码");
	}else{
		submit()
	}
};
function openTheMap(callback) {
    /*wx.ready(function () {
        wx.getLocation({
            type: 'wgs84',
            success: function (res) {
                // 地址解析:http://lbs.qq.com/javascript_v2/guide-service.html#link-four
                // 分享链接进这里会报错！！！！！
                let geocoder = new qq.maps.Geocoder({
                    complete: function (result) {
                        // return result.detail.addressComponents.city;
                        // alert(JSON.stringify(result.detail.addressComponents.city))
                        wx.openLocation({
                            latitude: res.latitude, // 纬度，浮点数，范围为90 ~ -90
                            longitude: res.longitude, // 经度，浮点数，范围为180 ~ -180。
                            name: '', // 位置名
                            address: result.detail.address, // 地址详情说明
                            scale: 25, // 地图缩放级别,整形值,范围从1~28。默认为最大
                            infoUrl: 'http://wechat.miniffee.com/coffee/html/index.html' // 在查看位置界面底部显示的超链接,可点击跳转
                        });
                    }
                })
                var coord = new qq.maps.LatLng(res.latitude, res.longitude)
                geocoder.getAddress(coord)
            },
            faild:function (res) {
                alert("定位失败，请扫描机身二维码登陆小啡");
            }
        })
    })*/
    window.location.href = "./tencentMap.html";
    var joinInfomation = {
    	"city":$("#city .form-text").text(),
		"company": $("#company").val(),
		"staffNum": $("#office .form-text").text(),
		"job":$("#job .form-text").text(),
		"phone":$("#phone").val()
	};
    sessionStorage.setItem("joinInfomation",JSON.stringify(joinInfomation));
}
